Skip to content

fix(OdfFile): keep shape rotation between 0 and 360 degrees - #355

Open
caspear wants to merge 4 commits into
Euro-Office:mainfrom
caspear:fix/odf-rotate-range
Open

caspear wants to merge 4 commits into
Euro-Office:mainfrom
caspear:fix/odf-rotate-range

Conversation

@caspear

@caspear caspear commented Nov 16, 2026

Copy link
Copy Markdown

Every open and save of an ODP, ODT, or an ODS adds a whole turn to each rotated shape. After 99 saves the int overflows, after which every rotated shape jumps to about 151 degrees rotation, and no error is shown.

Separately, the cast truncates instead of rounding, so each save can lose up to 1/60000 of a degree, always in the same direction, which adds up over many saves.

This fix normalises rotations to be bounded between 0 and 360 degrees, and rounds the values instead of simply truncating them.

Added two tests that run over a fixture with four rotated shapes. The tests:

  • Rotate by 0.3, which before drifted away due to truncating the value (it was .97, so almost entire unit discarded) and now keeps at the nearest unit to 0.3.
  • Rotate by -6 to test that normalisation to 0-360 degrees works
  • Rotate by 360 degrees, which the reader turns into 720 degrees, and then gets normalised to 0.
  • Rotate by whole turn written to 7 decimals, which comes out as 359.9999996 degrees, which triggers the final % 21600000 condition as it rounds up to 360 degrees.

Both tests fail on main, all 288 test_odf tests pass, and the conversion test output is unchanged.

Did some manual testing of this on my dev instance, saving and loading still works and produces no visible changes, or errors.

AI used extensively at every point in dev process, AI:

  • Found the issue
  • Fixed the issue
  • Wrote the tests (with some minor prodding to produce meaningful ones and not just to tick the box)
  • Convinced me it is worth pushing upstream

Human use limited to:

  • Doing the manual test
  • Reviewing the code
  • Shouting at the AI until it produced the fix in a shape that has a chance of being accepted upstream
  • Shouting at the AI to ELI5 the unfamiliar to me codebase until I felt comfortable subjecting another human to the AI's code

Assisted-by: ClaudeCode:claude-opus-5-5

The ODF reader converts draw:transform rotate(r) to a DrawingML rot of
360 - r degrees and does not bring it into one turn. The writer turns
rot back into rotate(-rot), so each open and save of an ODT, ODS or ODP
file adds a whole turn to every rotated shape:
rotate(-6.283185307179586), one turn, comes back as two. The shape looks
the same, but the value grows on each save, and after about 98 saves the
int rot overflows.

Bring the angle into 0..360 degrees with fmod before it is written.

Tested with OdpToPptxShape.RotationIsInOneTurn in test_odf: a slide with
rotate(0.3), rotate(-6) and a whole turn, written in full and with 7
decimals. It fails without the fix.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Anton Oussik <antonoussik@gmail.com>
rot counts in 1/60000 of a degree, and the cast to int truncated the
angle: rotate(0.3) is 342.81126614... degrees, 20568675.97 units, and
was written as 20568675, almost a whole unit less. The angle can creep
on each open of a saved file.

Round to the nearest unit. A value that rounds up to 360 degrees is
written as 0.

Tested with OdpToPptxShape.RotationIsRounded in test_odf, on the same
fixture: rotate(0.3) and rotate(-6) give 20568676 and 20626481, and the
whole turn with 7 decimals, which rounds up to 360 degrees, gives 0. It
fails without the fix.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Anton Oussik <antonoussik@gmail.com>

@chrip chrip left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Approve. Looks good from my side. The build and test checks have not run on this commit yet, so merge once they pass.

The fix in OdfFile/Reader/Converter/oox_drawing.cpp:893-895 is correct: serialize_xfrm is shared by the document, spreadsheet and presentation converters, so one change covers all three. I recalculated the four fixture angles by hand. The old code gives 20568675, 42226480, 43200000 and 43199999, the new code gives 20568676, 20626481, 0 and 0, which is what the tests expect. I read the tests and the fixture but did not build or run them.

praise: The fixture is four hand-written shapes in a 1.4 kB file, and each one covers a different case (rounding, a negative angle, an exact whole turn, a value that rounds up to 360 degrees). That makes the tests easy to check.

Assisted-by: ClaudeCode:claude-fable-5-2

@chrip
chrip enabled auto-merge (squash) November 16, 2026 13:49
@caspear

caspear commented Nov 16, 2026

Copy link
Copy Markdown
Author

Could someone give this build a poke please? :-)

Signed-off-by: Anton Oussik <antonoussik@gmail.com>
auto-merge was automatically disabled November 18, 2026 06:57

Head branch was pushed to by a user without write access

Signed-off-by: Anton Oussik <antonoussik@gmail.com>
@caspear

caspear commented Nov 27, 2026

Copy link
Copy Markdown
Author

Merged tree still passes test_odf locally. Please re-approve.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants